﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace FlyBird
{
    class GameFrontGround
    {
        //云彩类型个数
        private static readonly int CLOUND_COUNT = 2;
        //存放云彩的容器
        private List<Cloud> clouds;
        //云彩的飞行速度
        private static readonly int CLOUND_SPEED = 1;
        //使用到的图片资源
        private Image[] imgs;
        //用于产生随机数
        private Random random;

        //构造函数
        public GameFrontGround()
        {
            clouds = new List<Cloud>();
            imgs = new Image[CLOUND_COUNT];

            //容器中添加云彩的图片
            for (int i = 0; i < CLOUND_COUNT; i++)
            {
                imgs[i] = GameUtil.loadBufferedImage("img/cloud" + i + ".png");
            }
            random = new Random();

        }

        //绘制云彩
        public void draw(Graphics g)
        {
            logic();
            //遍历云彩容器绘制出来
            for (int i = 0; i < clouds.Count; i++)
            {
                clouds[i].draw(g);
            }
        }
        //云彩个数控制逻辑
        private void logic()
        {
            //随机生成
            //在0-500之间产生一个随机数，<20便生成云彩
            if (random.Next(0, 500) < 10)
            { 
                //云彩类型有不同
                Cloud cloud =  new Cloud(imgs[random.Next(CLOUND_COUNT)], CLOUND_SPEED, 600, random.Next(150));
                clouds.Add(cloud);
            }
            for (int i = 0; i < clouds.Count; i++)
            {
                Cloud cloud = clouds[i];
                if (cloud.isOutFrame())
                {
                    clouds.RemoveAt(i);
                    i--;
                }

            }
        }
    }
}
